import wx
try:
    from . import image
except ImportError:
    import image


def doBind(self, item, handler, updateUI=None):
    self.Bind(wx.EVT_TOOL, handler, item)
    if updateUI is not None:
        self.Bind(wx.EVT_UPDATE_UI, updateUI, item)

def fileMenu(self):
    _fileMenu = wx.Menu()
    doBind( self, _fileMenu.Append(-1, "&新建笔记", "New a file"), self.OnNewBook )
    item = wx.MenuItem(_fileMenu, -1, "&导入笔记\tCtrl+O", "")
    item.SetBitmap(image._rt_open.GetBitmap())
    doBind( self, _fileMenu.Append(item), self.OnOpenBook )
    item = wx.MenuItem(_fileMenu, -1, "&保存笔记\tCtrl+S", "")
    item.SetBitmap(image._rt_save.GetBitmap())
    doBind( self, _fileMenu.Append(item), self.OnSaveBook )
    doBind( self, _fileMenu.Append(-1, "&导出笔记\tF12", ""), self.OnExportBook )
    _fileMenu.AppendSeparator()
    doBind( self, _fileMenu.Append(-1, "&搜索笔记\tCtrl+P", ""), self.OnSearchBook)
    item = wx.MenuItem(_fileMenu, -1, "&笔记树\tCtrl+T", "")
    item.SetBitmap(image._menu_shu.GetBitmap())
    doBind( self, _fileMenu.Append(item), self.OnshuBook )
    _fileMenu.AppendSeparator()
    doBind( self, _fileMenu.Append(-1, "&退出\tCtrl+Q", ""), self.OnExitBook )
    return _fileMenu

def labelMenu(self):
    _labelMenu = wx.Menu()
    doBind( self, _labelMenu.Append(-1, "&新建标签\tCtrl+N", ""), self.OnNewLabel )
    doBind( self, _labelMenu.Append(-1, "&关闭标签\tCtrl+W", ""), self.OnCloseLabel )
    doBind( self, _labelMenu.Append(-1, "&删除标签\tCtrl+D", ""), self.OnDelLable )
    _Menu = wx.Menu()

    item = wx.MenuItem(_labelMenu, -1, "&表格", "")
    item.SetBitmap(image._menu_sheet.GetBitmap())
    doBind( self, _Menu.Append(item), self.OnNewLabel_table )
    item = wx.MenuItem(_labelMenu, -1, "&python", "")
    item.SetBitmap(image._menu_python.GetBitmap())
    doBind( self, _Menu.Append(item), self.OnNewLabel_python )
    item = wx.MenuItem(_labelMenu, -1, "&lua", "")
    item.SetBitmap(image._menu_lua.GetBitmap())
    doBind( self, _Menu.Append(item), self.OnNewLabel_lua )
    item = wx.MenuItem(_labelMenu, -1, "&python shell", "")
    item.SetBitmap(image._menu_shell.GetBitmap())
    doBind( self, _Menu.Append(item), self.OnNewLabel_shell )
    item = wx.MenuItem(_labelMenu, -1, "&俄罗斯方块", "")
    item.SetBitmap(image._menu_russia.GetBitmap())
    doBind( self, _Menu.Append(item), self.OnNewLabel_els )
    _labelMenu.AppendSeparator()
    _labelMenu.AppendSubMenu(_Menu, "新建其它标签")
    return _labelMenu

def editMenu(self):
    _editMenu = wx.Menu()
    doBind( self, _editMenu.Append(wx.ID_UNDO, "&撤销\tCtrl+Z"), self.ForwardEvent, self.ForwardEvent)
    doBind( self, _editMenu.Append(wx.ID_REDO, "&恢复\tCtrl+Y"), self.ForwardEvent, self.ForwardEvent )
    _editMenu.AppendSeparator()
    doBind( self, _editMenu.Append(wx.ID_CUT, "&剪切\tCtrl+X"), self.ForwardEvent, self.ForwardEvent )
    doBind( self, _editMenu.Append(wx.ID_COPY, "&复制\tCtrl+C"), self.ForwardEvent, self.ForwardEvent)
    doBind( self, _editMenu.Append(wx.ID_PASTE, "&粘贴\tCtrl+V"), self.ForwardEvent, self.ForwardEvent)
    doBind( self, _editMenu.Append(wx.ID_CLEAR, "&删除\tDel"), self.ForwardEvent, self.ForwardEvent)
    _editMenu.AppendSeparator()
    doBind( self, _editMenu.Append(wx.ID_SELECTALL, "&全选\tCtrl+A"), self.ForwardEvent, self.ForwardEvent )
    return _editMenu

def formatMenu(self):
    _formatMenu = wx.Menu()
    doBind( self, _formatMenu.AppendCheckItem(-1, "&加粗\tCtrl+B"), self.OnBold, self.OnUpdateBold)
    doBind( self, _formatMenu.AppendCheckItem(-1, "&斜体\tCtrl+I"), self.OnItalic, self.OnUpdateItalic)
    doBind( self, _formatMenu.AppendCheckItem(-1, "&下划线\tCtrl+U"), self.OnUnderline, self.OnUpdateUnderline)
    _formatMenu.AppendSeparator()
    doBind( self, _formatMenu.AppendCheckItem(-1, "左对齐"), self.OnAlignLeft, self.OnUpdateAlignLeft)
    doBind( self, _formatMenu.AppendCheckItem(-1, "居中"), self.OnAlignCenter, self.OnUpdateAlignCenter)
    doBind( self, _formatMenu.AppendCheckItem(-1, "右对齐"), self.OnAlignRight, self.OnUpdateAlignRight)
    _formatMenu.AppendSeparator()
    doBind( self, _formatMenu.Append(-1, "增加缩进"), self.OnIndentMore)
    doBind( self, _formatMenu.Append(-1, "减少缩进"), self.OnIndentLess)
    _formatMenu.AppendSeparator()
    doBind( self, _formatMenu.Append(-1, "增加段落间距"), self.OnParagraphSpacingMore)
    doBind( self, _formatMenu.Append(-1, "降低段落间距"), self.OnParagraphSpacingLess)
    _formatMenu.AppendSeparator()
    doBind( self, _formatMenu.Append(-1, "正常的行间距"), self.OnLineSpacingSingle)
    doBind( self, _formatMenu.Append(-1, "1.5行间距"), self.OnLineSpacingHalf)
    doBind( self, _formatMenu.Append(-1, "双行间距"), self.OnLineSpacingDouble)
    _formatMenu.AppendSeparator()
    doBind( self, _formatMenu.Append(-1, "字体"), self.OnFont)
    return _formatMenu

def MakeToolBar(self):
    tbar = wx.ToolBar(self)
    doBind( self, tbar.AddTool(-1, '', image._rt_open.GetBitmap(), shortHelp="打开"), self.OnFileOpen)
    doBind( self, tbar.AddTool(-1, '', image._rt_save.GetBitmap(), shortHelp="保存"), self.OnFileSave)
    tbar.AddSeparator()
    doBind( self, tbar.AddTool(wx.ID_CUT, '', image._rt_cut.GetBitmap(), shortHelp="剪切"), self.ForwardEvent, self.ForwardEvent)
    doBind( self, tbar.AddTool(wx.ID_COPY, '', image._rt_copy.GetBitmap(), shortHelp="复制"), self.ForwardEvent, self.ForwardEvent)
    doBind( self, tbar.AddTool(wx.ID_PASTE, '', image._rt_paste.GetBitmap(), shortHelp="粘贴"), self.ForwardEvent, self.ForwardEvent)
    tbar.AddSeparator()
    doBind( self, tbar.AddTool(wx.ID_UNDO, '', image._rt_undo.GetBitmap(), shortHelp="撤销"), self.ForwardEvent, self.ForwardEvent)
    doBind( self, tbar.AddTool(wx.ID_REDO, '', image._rt_redo.GetBitmap(), shortHelp="恢复"), self.ForwardEvent, self.ForwardEvent)
    tbar.AddSeparator()
    doBind( self, tbar.AddCheckTool(-1, '', image._rt_bold.GetBitmap(), shortHelp="加粗"), self.OnBold, self.OnUpdateBold)
    doBind( self, tbar.AddCheckTool(-1, '', image._rt_italic.GetBitmap(), shortHelp="斜体"), self.OnItalic, self.OnUpdateItalic)
    doBind( self, tbar.AddCheckTool(-1, '', image._rt_underline.GetBitmap(), shortHelp="下划线"), self.OnUnderline, self.OnUpdateUnderline)
    tbar.AddSeparator()
    doBind( self, tbar.AddCheckTool(-1, '', image._rt_alignleft.GetBitmap(), shortHelp="左对齐"), self.OnAlignLeft, self.OnUpdateAlignLeft)
    doBind( self, tbar.AddCheckTool(-1, '', image._rt_centre.GetBitmap(), shortHelp="居中"), self.OnAlignCenter, self.OnUpdateAlignCenter)
    doBind( self, tbar.AddCheckTool(-1, '', image._rt_alignright.GetBitmap(), shortHelp="右对齐"), self.OnAlignRight, self.OnUpdateAlignRight)
    tbar.AddSeparator()
    doBind( self, tbar.AddTool(-1, '', image._rt_indentless.GetBitmap(), shortHelp="减少缩进"), self.OnIndentLess)
    doBind( self, tbar.AddTool(-1, '', image._rt_indentmore.GetBitmap(), shortHelp="增加缩进"), self.OnIndentMore)
    tbar.AddSeparator()
    doBind( self, tbar.AddTool(-1, '', image._rt_font.GetBitmap(), shortHelp="字体"), self.OnFont)
    doBind( self, tbar.AddTool(-1, '', image._rt_colour.GetBitmap(), shortHelp="字体颜色"), self.OnColour)
    tbar.AddSeparator()

    doBind( self, tbar.AddTool(-1, '', image._rt_addparagraph.GetBitmap(), shortHelp="增加段落间距"), self.OnParagraphSpacingMore)
    doBind( self, tbar.AddTool(-1, '', image._rt_delparagraph.GetBitmap(), shortHelp="降低段落间距"), self.OnParagraphSpacingLess)
    tbar.AddSeparator()
    doBind( self, tbar.AddTool(-1, '', image._rt_linespacing1.GetBitmap(), shortHelp="正常的行间距"), self.OnLineSpacingSingle)
    doBind( self, tbar.AddTool(-1, '', image._rt_linespacing2.GetBitmap(), shortHelp="双行间距"), self.OnLineSpacingDouble)
    #tbar.Realize()
    return tbar


def ctrlbind(self):
    ensic = []
    ensic.append(wx.AcceleratorEntry(wx.ACCEL_CTRL, ord('b'), self.GetId()))
    ensic.append(wx.AcceleratorEntry(wx.ACCEL_CTRL, ord('l'), self.GetId()))
    ensic.append(wx.AcceleratorEntry(wx.ACCEL_CTRL, ord('u'), self.GetId()))
    self.SetAcceleratorTable(wx.AcceleratorTable(ensic))
